var subid = '';
$(function  () {
   
     //获取学科
     $.post(
        ipurl+'/subject/get',
        function(result) {
            if(result.code == 200){
                var menulist = result.data.results;
                var menuhtml = '';
                for(var i=0;i<menulist.length;i++){
                    menuhtml+='<button class="layui-btn" onclick="gettask('+menulist[i].ID+','+"'"+menulist[i].name+"'"+')">'+menulist[i].name+'</button>';
                }
                $("#subject").html(menuhtml);
            }
        }
    );
})

function gettask(id,name){

    $('#tnow').css('display','');
    $('#tnow').html("当前选择学科为:"+name);
    //用户ID
    var uid = $.cookie("lid");
    //学科ID
    subid=id;
    //查看学生此门科目是否交过作业
    $.ajax({
        url: ipurl+'/task/getbyid',
        data: {
            rid:uid,
            sid:subid
        },
        type: "POST",
        //dataType: "json",
        success:function(resultper){
            if(resultper.data==0){
                //没交作业
                $('#Situation').css('display','');
                $('#Situation').html('此科目您未交作业请添加');
                $('#tianjia').css('display','');
                $('#tasktable').css('display','none');
            }else{
                //已交作业
                $('#Situation').css('display','');
                $('#Situation').html('此科目您已提交作业');
                $('#tasktable').css('display','');
                var userlist = resultper.data.results;
                var userhtml = '';
                for(var i=0;i<userlist.length;i++){
                    userhtml+='<tr>';
                    userhtml+='<td>';
                    userhtml+=userlist[i].title;
                    userhtml+='</td>';
                    userhtml+='<td>';
                    userhtml+=userlist[i].content;
                    userhtml+='</td>';
                    userhtml+='<td>';
                    userhtml+=userlist[i].achievement;
                    userhtml+='</td>';
                    userhtml+='</tr>';
                }
                $("#taskbody").html(userhtml);


            }
        },
        complete: function(data) {
        }
    
    });

    //$('#tianjia').css('display','');

    
}
    
function task_add(title,url,w,h){
    //$.cookie("prid", roleid, { expires: 7 });
    $.cookie("tsid", subid, { expires: 7 });

    x_admin_show(title,url,w,h);
}

/*权限-删除*/
function per_del(obj,id){
    layer.confirm('确认要删除吗？',function(index){
        //发异步删除数据
        $(obj).parents("tr").remove();
        layer.msg('已删除!',{icon:1,time:1000});
        $.post(
            ipurl+'/per/del',
            {
              id: id
            },
            function(result) {
              console.log(result);
                // layer.open({
                //     content: '添加成功',
                //     end: function(index, layero){
                     
                //     }
                // });
            }
      );
    });
}

